package com.focusai.efairy.ui.adapter;

import android.content.Context;
import android.view.View;

import com.focusai.efairy.R;
import com.focusai.efairy.model.dev.DeviceItem;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerAdapter;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerViewHolder;
import com.focusai.efairy.utils.Constants;
import com.focusai.efairy.utils.StrByCodeUtils;

/**
 * Created by luo_guangwen on 2017/7/31.
 */

public class DevListAdapter extends BaseRecyclerAdapter<DeviceItem> {
    private OnDevDetailClickListener listener;
    public DevListAdapter(Context context) {
        super(context);
    }
    @Override
    protected int getItemLayoutId() {
        return R.layout.item_dev_list;
    }

    @Override
    protected void onBindBaseRecyclerViewHolder(BaseRecyclerViewHolder holder, int position) {
         final DeviceItem item = mList.get(position);
        holder.setText(R.id.text_dev_name, item.efairydevice_name);
        if (item.efairydevice_is_online == Constants.DEVICE_IS_ONLINE) {
            holder.setText(R.id.text_dev_state, R.string.online);
            holder.setTextColor(R.id.text_dev_state, mContext.getResources().getColor(R.color.light_green));
            holder.setSrcBackground(R.id.img_dev, R.drawable.icon_dev_online);
        } else {
            holder.setText(R.id.text_dev_state, R.string.unline);
            holder.setTextColor(R.id.text_dev_state, mContext.getResources().getColor(R.color.light_gray));
            holder.setSrcBackground(R.id.img_dev, R.drawable.icon_dev_unonline);
        }
        if (listener != null){
            holder.getView(R.id.iv_detail).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onDevDetailClickListener(item);
                }
            });
        }

        holder.setText(R.id.text_dev_status, StrByCodeUtils.getStatusByDevState(item.efairydevice_alarm_id));
        holder.setTextColor(R.id.text_dev_status,mContext.getResources().getColor(StrByCodeUtils.getColorByDevState(item.efairydevice_alarm_id)));

    }

    public void setListener(OnDevDetailClickListener listener) {
        this.listener = listener;
    }

    public  interface OnDevDetailClickListener{
        void onDevDetailClickListener(DeviceItem item);
    }
}
